package zisu.algorithm.algorithm.BST.Map;

import zisu.algorithm.algorithm.BST.FileOperation;
import zisu.algorithm.algorithm.Map.LinkedListMap;

import java.util.ArrayList;

/**
 * @Author: 蔡翔
 * @Date: 2019/12/21 20:08
 * @Version 1.0
 */
public class Main {
    private static double testMap(Map<String,Integer> map , String fileName){
        long startTime = System.nanoTime();

        System.out.println("pride-and-prejudice");
        ArrayList<String> word1 = new ArrayList<>();
        FileOperation.readFile("pride-and-prejudice.txt",word1);
        System.out.println("Total words:"+word1.size());

        for(String word:word1){
            if(map.contains(word)){
                map.set(word,map.get(word)+1);
            }else {
                map.add(word,1);
            }
        }

        System.out.println("Total different words:"+map.getSize());
        System.out.println("Frequent of PRIDE:"+map.get("pride"));
        System.out.println("Frequent of prejudice:"+map.get("prejudice"));

        long endTime = System.nanoTime();
        return (endTime - startTime)/1000000000.0;
    }

    public static void main(String[] args) {
        String fileName = "pride-and-prejudice.txt";
        BSTMap<String,Integer> bstMap = new BSTMap<>();
        double v = testMap(bstMap, fileName);
        System.out.println("BST Map:"+ v +"s");

        System.out.println("==============================================");

        String fileNames = "pride-and-prejudice.txt";
        LinkedListMap<String,Integer> linkedListMap = new LinkedListMap<>();
        double a = testMap(linkedListMap, fileNames);
        System.out.println("LinkedList Map:"+ a +"s");
    }
}